package wangxiaotao.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

//    @Override//添加路路径匹配规则
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        UrlPathHelper urlPathHelper = new UrlPathHelper();
//        //设置不移除分号后面的内容  矩阵变量的支持
//        urlPathHelper.setRemoveSemicolonContent(false);
//        configurer.setUrlPathHelper(urlPathHelper);
//
//        //配置路径前缀:对含有AddUserPath注解的controller添加/user地址前缀
//        //作用相当于requestMapping注解添加路径
//        configurer.addPathPrefix("/user", new Predicate<Class<?>>() {
//            @Override
//            public boolean test(Class<?> aClass) {
//                return aClass.isAnnotationPresent(AddUserPath.class);
//            }
//        });
//    }

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new RequestInterceptor())
//                .addPathPatterns("/**")//拦截所有请求
//                .excludePathPatterns("/index.html","/");//放行首页
//    }

    /**
     * 跨域支持
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
//                .allowedOrigins("*")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
